package biz.inspeed.test.thread1;

public class Turning628 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int flag = 0;
		Object lock = new Object();
		new Thread62803(lock,flag).start();
		new Thread62824(lock,flag).start();
		new Thread62825(lock,flag).start();
	}

}

class Thread62803 extends Thread {
	private int flag = 0;
	private Object lock;

	public Thread62803(Object lock, int flag) {
		this.flag = flag;
		this.lock = lock;
	}

	@Override
	public void run() {
		while (true) {
			synchronized (lock) {
				if (flag % 3 == 0) {
					flag++;
					System.out.println("3 ������"+this.flag);
				}
				lock.notifyAll();
				try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

class Thread62824 extends Thread {
	private int flag = 0;
	private Object lock;

	public Thread62824(Object lock, int flag) {
		this.flag = flag;
		this.lock = lock;
	}

	@Override
	public void run() {
		while (true) {
			synchronized (lock) {
				if (flag % 3 == 1) {
					flag++;
					System.out.println("3 ������ ��һ"+this.flag);
				}
				lock.notifyAll();
				try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

class Thread62825 extends Thread {
	private int flag = 0;
	private Object lock;

	public Thread62825(Object lock, int flag) {
		this.flag = flag;
		this.lock = lock;
	}

	@Override
	public void run() {

		while (true) {
			synchronized (lock) {
				if (flag % 3 == 2) {
					flag++;
					System.out.println("3 ������ ���" +this.flag);
				}
				lock.notifyAll();
				try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
